import { Component, OnInit } from '@angular/core';
import { TagItem, MessageboxService } from '@iux/live';
import { Observable } from 'rxjs';

@Component({
  selector: 'app-demo3',
  templateUrl: './demo3.component.html',
  styles: []
})
export class Demo3Component implements OnInit {

  data: TagItem[];

  constructor(private messageBox: MessageboxService) { }

  ngOnInit() {
    this.initData();
  }

  initData() {
    this.data = this.initTag(10);
  }

  initTag(length: number = 10) {
    return Array.from({ length }).map((item, key) => ({
      label: `Tag${key + 1}`,
      removable: true,
    }));
  }

  beforeRemove = (source) => new Observable((observer) => {
    this.messageBox.confirm({
      lvHeader: 'Delete',
      lvContent: 'Do you confirm deletion?',
      lvCancel: () => {
        observer.next(false);
        observer.complete();
      },
      lvOk: () => {
        observer.next(true);
      }
    });
  })

  beforeClearAll = () => true

  clearAll(source) { console.log(source); }

  remove(source) { console.log(source); }

}
